package com.genghis.rapidcrm.web.view;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author xulixin
 */
public class RapidViewer {

    private final RapidActionView freeMarkerView;

    public RapidViewer(RapidActionView freeMarkerView) {
        this.freeMarkerView = freeMarkerView;
    }

    private final Map<String, Object> model = new LinkedHashMap<>();

    public Map<String, Object> getModel() {
        return model;
    }

    public void assign(String key, Object value) {
        model.put(key, value);
    }

    public void view(String templateUri, HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        view(templateUri, null, request, response);
    }
    public void view(String templateUri, String module, HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        freeMarkerView.doRapidViewRender(templateUri, module, this, request, response);
    }
}
